package services;

import java.util.ArrayList;
import java.util.List;

import business.Company;
import business.CompanyCampaign;

import dao.Filter;
import dao.ObjectDao;


public class CompanyService {

	public Company getCompany(String cuit)
	{
		List<Filter> filters = new ArrayList<Filter>();		
		Filter filter = new Filter(Filter.STRING_FILTER, "EMP.CUIT", Filter.EQUAL_OPERATOR,cuit,true);
		filters.add(filter);
						
		List<Company> empresas = new ObjectDao().getCompanies(filters, ObjectDao.AND_OPERATOR);

		if(empresas != null && empresas.size() == 1)
		{
			return empresas.get(0);
		}
		else
		{
			return null;
		}
	}
	
	public List<CompanyCampaign> getCompanyCampaignsByUser(Long userID)
	{
		ObjectDao dao= new ObjectDao();
		
		List<CompanyCampaign> pollCampaignList = dao.getLogingCompanyCampaings(userID);
		if(pollCampaignList != null && pollCampaignList.size() > 0)
		{
			return pollCampaignList;
		}
		else
		{
			return null;
		}
	}
	
	public CompanyCampaign getCompanyCampaign(Long companyCampaignID)
	{
		ObjectDao dao= new ObjectDao();
		List<Filter> filters = new ArrayList<Filter>();
		
		Filter filter = new Filter(Filter.NUMERIC_FILTER, "EMP_CAM.ID_EMP_CAMP", Filter.EQUAL_OPERATOR,companyCampaignID,true);
		filters.add(filter);
		List<CompanyCampaign> pollCampaignList = dao.getCompanyCampaigns(filters, ObjectDao.AND_OPERATOR);
		if(pollCampaignList != null && pollCampaignList.size() == 1)
		{
			return pollCampaignList.get(0);
		}
		else
		{
			return null;
		}
	}
}
